﻿@{
    Layout = null;
}

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>部门管理</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="~/layuiadmin/layui/css/layui.css" media="all">
    <style>
        html, body {
            height: 100%;
            margin: 0;
            padding: 0;
            font-size: 12px;
        }

        div {
            -moz-box-sizing: border-box; /*Firefox3.5+*/
            -webkit-box-sizing: border-box; /*Safari3.2+*/
            -o-box-sizing: border-box; /*Opera9.6*/
            -ms-box-sizing: border-box; /*IE8*/
            box-sizing: border-box; /*W3C标准(IE9+，Safari5.1+,Chrome10.0+,Opera10.6+都符合box-sizing的w3c标准语法)*/
        }

        .dHead {
            height: 55px;
            width: 100%;
            position: fixed;
            z-index: 5;
            top: 0;
            overflow-x: auto;
            padding: 10px;
        }

        .dBody {
            width: 98%;
            overflow: auto;
            top: 55px;
            position: absolute;
            z-index: 10;
            bottom: 5px;
            margin-left: 10px;
        }
  
    </style>

</head>
<body>
    @Html.AntiForgeryToken()
    <div style="height:100%;">
        <div class="dHead">

            <button class="layui-btn layui-btn-sm" lay-event="openAll" id="btnOpenAll" onclick="openAll();">展开或折叠全部</button>

            @if (ViewBag.CoreUploadEdit)
            {
                <button class="layui-btn layui-btn-sm" lay-event="add" id="btnAdd" onclick="OnAdd();">上传文件</button>
            }
        </div>


        <div class="dBody">
            <table class="layui-hidden" id="treeTable" lay-filter="treeTable"></table>
        </div>
    </div>
<script src="~/layuiadmin/layui/layui.all.js"></script>
    <script>
        var editObj = null, ptable = null, treeGrid = null, tableId = 'treeTable', layer = null, $;
        layui.config({
            base: '../layuiadmin/' , version: "@(@StaticConfig.StaticConfigVersion)"
        }).extend({
            index: 'lib/index' //主入口模块
        }).use(['index', 'treeGrid'], function () {
            $ = layui.$;
            treeGrid = layui.treeGrid;//很重要
            layer = layui.layer;

            ptable = treeGrid.render({
                id: tableId
                , elem: '#' + tableId
                //, url: '../layuiadmin/json/treeGrid/treeData.json'
                , url: 'PostFileListJson'
                , cellMinWidth: 100//单元格最小宽度
                , idField: 'ID'//必須字段
                , treeId: 'ID'//树形id字段名称
                , treeUpId: 'ParentID'//树形父id字段名称
                , treeShowName: 'FileName'//以树形式显示的字段
                , heightRemove: [".dHead", 20]//不计算的高度,表格设定的是固定高度，此项不生效
                , height: '100%'
                , isFilter: false
                , iconOpen: true//是否显示图标【默认显示】
                , isOpenDefault: true//节点默认是展开还是折叠【默认展开】
                , loading: true
                , method: 'post'
                , isPage: false
                , cols: [[
                    { type: 'numbers' }
                    , { field: 'FileName', width: 0, title: '文件名称' }
                    , { field: 'FileSize', width: 200, title: '大小' }
                    , { field: 'FileDate', width: 200, title: '上传日期' }
                    , {
                        fixed: 'right', align: 'center', title: '操作', width: 80, templet: function (d) {
                            if (!(d.FileSize === "")) {
                                return '<button class="layui-btn layui-btn-xs" lay-event="downFile">下载</button>';
                            } else {
                                return '<span></span>';
                            }
                        }
                    }
                ]]
                , where: { __RequestVerificationToken: document.getElementsByName("__RequestVerificationToken")[0].value }

            });
            treeGrid.on('tool(' + tableId + ')', function (obj) {
                if (obj.event === "downFile") {//删除
                    top.layer.confirm('真的要下载此条记录么？', function (index) {

                        @*window.location.href = "@Url.Action("DownLoad")?file=" + obj.data.FilePath;*@
                        window.location.href = "@Url.Action("DownloadFile")?filePath=" + obj.data.FilePath;
                        //在顶层弹出需要手动关闭
                        top.layer.close(index);
                    });
                }
            });
        });

        function reload() {//reload
            treeGrid.reload(tableId);
        }

        function openAll() {//展开或折叠全部
            var treedata = treeGrid.getDataTreeList(tableId);
            treeGrid.treeOpenAll(tableId, !treedata[0][treeGrid.config.cols.isOpen]);
        }

        function OnAdd() {
            top.layer.open({
                type: 2,
                resize: false,
                content: '/Admin/UploadFiles',
                title: ["只能上传文件格式【zip】【rar】【7z】【docx】【pptx】【xls】【xlsx】,单个大小100MB",'color:red;'],
                area: ['800px', '550px'],
                cancel: function () {
                    reload();
                }
            });
        }

    </script>
</body>

</html>